import re

from lxml import etree

import requests
def group_0(json_info,cookie_end,DOMAIN):
    url = f"{DOMAIN}//phis/app/ehr/index/{json_info}"
    "http://10.216.11.24:8306/phis/app/svc/first/soap/create/1?ehrBaseId=530008"
    headers = {
        "cookie": f"JSESSIONID={cookie_end}",
        "user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36"
    }

    """group_0"""
    dict_group_0 = {'姓名-头部': '', '性别-头部': '', '出生日期-头部': '', '签约截止时间-头部': '', '签约医生': '', '人群分类_头部': '', '慢病分类': '',
                         '签约护士': '', '待服务项': None, '药物过敏史': ''}

    response_0 = requests.get(url, headers=headers)
    tree2 = etree.HTML(response_0.text)

    name = tree2.xpath('//td[@id="name"]/text()')[0]
    result = re.sub(r'[^\u4e00-\u9fa5]', '', name)

    dict_group_0["姓名-头部"] = result

    xingbie = tree2.xpath('//td[@id="gender"]/text()')[0]
    result = re.sub(r'[^\u4e00-\u9fa5]', '', xingbie)
    dict_group_0["性别-头部"] = result

    date = tree2.xpath('//td[@id="birthDate"]/text()')[0].strip()
    dict_group_0["出生日期-头部"] = date

    sign_date = tree2.xpath('//td[font[@color="red" and contains(text(), "签约截止时间")]]/following-sibling::td[1]/text()')
    sign_date = sign_date[0].strip() if sign_date else None
    dict_group_0["签约截止时间-头部"] = sign_date

    tds = tree2.xpath('//td[@class="font_weight"]/text()')
    result = [re.sub(r'[^\u4e00-\u9fa5]', '', biaotou) for biaotou in tds]
    if "人群分类" in result:
        result.remove("人群分类")
        result.insert(1, "人群分类_头部")

    result_value = tree2.xpath('//td[@class="thumbnail" and @nowrap="nowrap"]/text()')
    result_value = [re.sub(r'[^\u4e00-\u9fa5]', '', result) for result in result_value]

    result_value.insert(4, "")
#
    for key, value in zip(result, result_value):
        dict_group_0[key] = value
    if dict_group_0["签约截止时间-头部"] == "":
        dict_group_0["签约截止时间-头部"] = None
    if dict_group_0["签约医生"] == "":
        dict_group_0["签约医生"] = None
    if dict_group_0["签约护士"]=="":
        dict_group_0["签约护士"] = None
    if dict_group_0["待服务项"] == "":
        dict_group_0["待服务项"]= None
    print(dict_group_0)
    return dict_group_0
if __name__ == '__main__':
    print(group_0("530008", "4899910587A9C3397018041FC198340F","http://10.216.11.24:8306"))